﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace YXShop.Web.membercenter.shop.shop_administer
{
    public partial class shop_friendship_link : System.Web.UI.Page
    {
        YXShop.BLL.Accessories.Hailhellowlink linkBll = new YXShop.BLL.Accessories.Hailhellowlink();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                if (ChangeHope.WebPage.PageRequest.GetFormString("Option") != string.Empty && ChangeHope.WebPage.PageRequest.GetFormString("id") != "")
                {
                    string types = Request["Option"].Trim();
                    string id = ChangeHope.WebPage.PageRequest.GetFormString("id");
                    if (types == "del")
                    {
                        linkBll.Delete(Convert.ToInt32(id));
                    }
                    if (types == "delAll")
                    {
                        linkBll.DeleteAll(id);
                    }
                    if (types == "leavel")
                    {
                        int number=ChangeHope.WebPage.PageRequest.GetFormInt("leavelID");
                        UpdateFirst(Convert.ToInt32(id),number);
                    }
                    Response.End();
                    return;
                }
                this.litlist.Text = GetList();
            }
        }
        private string GetList()
        {   
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            ChangeHope.DataBase.DataByPage dataPage=new ChangeHope.DataBase.DataByPage();
            if(Session["MemberID"]!=null)
            {
               dataPage = linkBll.GetList(" [order by] sitelevel DESC ", 20, " and putoutid=" + Session["MemberID"].ToString());
            }
            table.AddHeadCol("","<input id=\"chall\" type=\"checkbox\" onclick=\"SelectAll(chall)\" />全选");
            table.AddHeadCol("","序号");
            table.AddHeadCol("","链接标题");
            table.AddHeadCol("","点击数");
            table.AddHeadCol("","优先级");
            table.AddHeadCol("","审核状态");
            table.AddHeadCol("","操作");
            table.AddRow();
            if(dataPage.DataReader!=null)
            {
                int curpage = ChangeHope.WebPage.PageRequest.GetInt("pageindex");
                if (curpage < 0)
                {
                    curpage = 1;
                }
                int count = 0;
                while(dataPage.DataReader.Read())
                {
                    count++;
                    string No = (15 * (curpage - 1) + count).ToString();
                    table.AddCol("<input id=\"cbTm\"  type=\"checkbox\" value=\"" + dataPage.DataReader["id"].ToString() + "\" />");
                    table.AddCol(No);
                    table.AddCol(dataPage.DataReader["sitename"].ToString());
                    table.AddCol(dataPage.DataReader["siteclickcount"].ToString());
                    table.AddCol(string.Format("<input id='leavel{0}' value='{1}' size='5' onblur='SetLeavel({0})'/>", dataPage.DataReader["id"].ToString(), dataPage.DataReader["sitelevel"].ToString()));
                    table.AddCol(dataPage.DataReader["sitestate"].ToString()=="0"?"未审核":"已审核");
                    string url = YXShop.TemplateAction.Common.UrlStr("shop_friendship_edit", "linkId=" + dataPage.DataReader["id"], "membercenter/shop/shop_administer/");
                    table.AddCol("<a href=\"" + url + "\">编辑</a>&nbsp;<a href=\"#\" onclick='Del("+dataPage.DataReader["id"]+")'>删除</a>");
                    table.AddRow();
                }
            }
            string view = table.GetTable() + dataPage.ReceptionToolBar;
            dataPage.Dispose();
            dataPage = null;
            return view;
        }
        //修改
        private void UpdateFirst(int id,int number)
        {
            int count=linkBll.Amend(id, "sitelevel", number);
            if(count>0)
            {
                Response.Write("ok");
            }
        }
    }
}
